package org.jsola.hr.helper;

import org.jsola.common.ClassKit;
import org.jsola.common.DateKit;
import org.jsola.common.SafeKit;
import org.jsola.hr.constant.EducationLevelEnum;
import org.jsola.hr.dto.EmpEducationAddDTO;
import org.jsola.hr.dto.EmpEducationUpdateDTO;
import org.jsola.hr.entity.EmpEducationDO;
import org.jsola.hr.query.EmpEducationQuery;
import org.jsola.hr.service.IEmpEducationService;
import org.jsola.hr.vo.EmpEducationVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.util.CollectionUtils;

import java.util.Date;
import java.util.List;

import static org.jsola.hr.core.AbstractTest.SITE_ID;



/**
 * 员工教育经历
 *
 * @author zhr
 */
@Component
public class EmpEducationTestHelper extends BaseTestHelper {
    
    @Autowired
    private IEmpEducationService empEducationService;

    /**
     * 生成add测试数据
     * @return EmpEducationAddDTO
     */
    public EmpEducationAddDTO getEmpEducationAddDTO(){
        EmpEducationAddDTO empEducationAddDTO = new EmpEducationAddDTO();
        empEducationAddDTO.setEmpId(getRandomValue("varchar",32));
        empEducationAddDTO.setGraCollege(getRandomValue("varchar",255));
        empEducationAddDTO.setGraCerNumber(getRandomValue("varchar",255));
        empEducationAddDTO.setIsLehramt(SafeKit.getBoolean(getRandomValue("bigint",1)));
        empEducationAddDTO.setMajor(getRandomValue("varchar",255));
        empEducationAddDTO.setEducation(EducationLevelEnum.JUNIOR_HIGH_SCHOOL.getValue());
        empEducationAddDTO.setTeaMethods(getRandomValue("varchar",50));
        empEducationAddDTO.setStartTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empEducationAddDTO.setEndTime((Date)ClassKit.getObjectValue(getRandomValue("datetime",0),"java.util.Date"));
        empEducationAddDTO.setIsFirstEdu(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empEducationAddDTO.setIsHighestEdu(SafeKit.getBoolean(getRandomValue("bigint",1)));
        empEducationAddDTO.setDegreeType(SafeKit.getInteger(getRandomValue("tinyint",4)));
        empEducationAddDTO.setDegreeName(getRandomValue("varchar",100));
        empEducationAddDTO.setDegreeNumber(getRandomValue("varchar",255));
        empEducationAddDTO.setEducationRemark(getRandomValue("text",2147483647));
        empEducationAddDTO.setIsFirstDegree(SafeKit.getBoolean(getRandomValue("bigint",1)));
        empEducationAddDTO.setIsHighestDegree(SafeKit.getBoolean(getRandomValue("tinyint",1)));
        empEducationAddDTO.setCompanyId(getRandomValue("varchar",32));
        return empEducationAddDTO;
    }


    /**
     * 生成update测试数据
     * @return EmpEducationUpdateDTO
     */
    public EmpEducationUpdateDTO getEmpEducationUpdateDTO(EmpEducationVO empEducationVO){
        return empEducationService.selectDOById(empEducationVO.getId(), SITE_ID).to(EmpEducationUpdateDTO.class);
    }

    /**
     * 生成查询数据
     * @return EmpEducationQuery
     */
    public EmpEducationQuery getEmpEducationQuery() {
        EmpEducationQuery empEducationQuery = new EmpEducationQuery();
        List<EmpEducationDO> empEducationDOList = empEducationService.list(new EmpEducationDO(),SITE_ID);
        if (!CollectionUtils.isEmpty(empEducationDOList)) {
            EmpEducationDO empEducationDO = empEducationDOList.get(0);
            empEducationQuery = empEducationDO.to(EmpEducationQuery.class);
            if (empEducationDO.getStartTime() != null) {
                empEducationQuery.setStartTimeStart(DateKit.getBeforeDay(empEducationDO.getStartTime(),-1));
                empEducationQuery.setStartTimeEnd(DateKit.getBeforeDay(empEducationDO.getStartTime(),1));
            }
            if (empEducationDO.getEndTime() != null) {
                empEducationQuery.setEndTimeStart(DateKit.getBeforeDay(empEducationDO.getEndTime(),-1));
                empEducationQuery.setEndTimeEnd(DateKit.getBeforeDay(empEducationDO.getEndTime(),1));
            }
            if (empEducationDO.getGmtCreate() != null) {
                empEducationQuery.setGmtCreateStart(DateKit.getBeforeDay(empEducationDO.getGmtCreate(),-1));
                empEducationQuery.setGmtCreateEnd(DateKit.getBeforeDay(empEducationDO.getGmtCreate(),1));
            }
            if (empEducationDO.getGmtModified() != null) {
                empEducationQuery.setGmtModifiedStart(DateKit.getBeforeDay(empEducationDO.getGmtModified(),-1));
                empEducationQuery.setGmtModifiedEnd(DateKit.getBeforeDay(empEducationDO.getGmtModified(),1));
            }
        }
        return empEducationQuery;
    }

    /**
     * 保存示例
     * @return EmpEducationVO
     */
    public EmpEducationVO saveEmpEducationExample(){
        EmpEducationAddDTO addDTO = this.getEmpEducationAddDTO();
        EmpEducationVO empEducationVO = empEducationService.save(addDTO,buildTokenUser());
        return empEducationVO;
    }


}

